home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 4 / Mac Giga-ROM 4.0 - 1993.toast / FILES / DEV / C-H / CMacPrimer.cpt / Mondrian ƒ / mondrian.c < prev   
Encoding:
C/C++ Source or Header  |  1989-12-17  |  1.6 KB  |  87 lines  |  [TEXT/KAHL]

  1. #define BASE_RES_ID            400
  2. #define NIL_POINTER            0L
  3. #define MOVE_TO_FRONT        -1L
  4. #define REMOVE_ALL_EVENTS    0
  5. #define OVAL_WIDTH            20
  6. #define OVAL_HEIGHT            20
  7. #define PEN_WIDTH            1
  8. #define PEN_HEIGHT            1
  9. #define START_DEGREES        330
  10. #define ARC_DEGREES            60
  11.  
  12.  
  13. WindowPtr    gDrawWindow;
  14. long    gFillColor = blackColor;
  15.  
  16. main()
  17. {
  18.     ToolBoxInit();
  19.     WindowInit();
  20.     MainLoop();
  21. }
  22.  
  23. ToolBoxInit()
  24. {
  25.     InitGraf (&thePort);
  26.     InitFonts();
  27.     FlushEvents(everyEvent,REMOVE_ALL_EVENTS);
  28.     InitWindows();
  29.     InitMenus();
  30.     TEInit();
  31.     InitDialogs(NIL_POINTER);
  32.     InitCursor();
  33. }
  34.  
  35. WindowInit()
  36. {
  37.     gDrawWindow = GetNewWindow( BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT);
  38.     ShowWindow(gDrawWindow);
  39.     SetPort(gDrawWindow);
  40.     PenSize(PEN_WIDTH, PEN_HEIGHT);
  41.     PenPat(black);
  42. }
  43.  
  44. MainLoop()
  45. {
  46.     GetDateTime(&randSeed);
  47.     while(!Button())
  48.     {
  49.         DrawRandomRect();
  50.         if(gFillColor==blackColor)
  51.             gFillColor=whiteColor;
  52.         else
  53.             gFillColor=blackColor;
  54.     }
  55. }
  56.  
  57. DrawRandomRect()
  58. {
  59.     Rect myRect;
  60.     
  61.     RandomRect(&myRect, gDrawWindow);
  62.     ForeColor(gFillColor);
  63.     PaintArc(&myRect, START_DEGREES, ARC_DEGREES);
  64. }
  65.  
  66. RandomRect(myRectPtr,boundingWindow)
  67. Rect        *myRectPtr;
  68. WindowPtr    boundingWindow;
  69. {
  70.     myRectPtr->left = Randomize(boundingWindow->portRect.right
  71.         -boundingWindow->portRect.left);
  72.     myRectPtr->right = Randomize(boundingWindow->portRect.right
  73.         -boundingWindow->portRect.left);
  74.     myRectPtr->top = Randomize(boundingWindow->portRect.bottom
  75.         -boundingWindow->portRect.top);
  76.     myRectPtr->bottom = Randomize(boundingWindow->portRect.bottom
  77.         -boundingWindow->portRect.top);
  78. }
  79.  
  80. Randomize (range)
  81. int    range;
  82. {
  83.     long    rawResult;
  84.     rawResult=Random();
  85.     if(rawResult<0) rawResult *= -1;
  86.         return((rawResult*range)/32768);
  87. }